package com.winai.launcher.manager;

import com.ks.projectbasictools.utils.LogUtils;
import com.winai.launcher.bean.db.Device;

import org.litepal.LitePal;

import java.util.List;

public class DeviceManager {

    /**
     * 说明：更新数据到数据库
     */
    public static void updateDeviceToDB(Device device) {
        device.saveOrUpdate("deviceId = ?", device.getDeviceId());
        LogUtils.i("Lite==> 已更新Device表中的数据");
    }

    /**
     * 说明：从数据库里面获取设备
     */
    public static Device loadDeviceFromDB(String deviceId) {
        List<Device> devices = LitePal.where("deviceId = ?", deviceId).find(Device.class);
        LogUtils.i("Lite==> 查找到本地数据库的设备对象deviceId = " + deviceId + ",deviceList.size = " + devices.size());
        if (devices.size() > 0) {
            return devices.get(0);
        } else {
            return null;
        }
    }
}
